/////////////////////////////////////////////////////////////////////////////
// Name:        ax_menu_modal.h
// Purpose:     Modal menu class
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_MENU_MODAL_H_
#define _AX_MENU_MODAL_H_

/*
 * Includes
 */

#include "ax/ax_menu.h"
 
/*
 * Forward declarations
 */

class AxResource;
class AxMenuController;
class wxEventLoop;

/**
    @class AxModalMenu

    A class to show a menu 'modally', that is, interrupting program flow and not allowing
    the user to make other selections.

    @category{ax}
 */

class AxModalMenu: public wxEvtHandler
{
    DECLARE_CLASS( AxModalMenu )

public:
// Constructors

    AxModalMenu() { Init(); }
    AxModalMenu(AxMenuController* controller, AxMenuItem* item = NULL);
    
    ~AxModalMenu();

// Operations

    void Init();

    /// Starts showing the menu modally. If childMenu is specified,
    /// it will be shown immediately instead of the top-level menu.
    virtual wxString ShowModal(AxMenu* childMenu = NULL);

    /// Terminates the modal loop
    virtual bool EndModal(const wxString& returnCode);

    /// 'Hides' the menu (restores previous)
    virtual bool Hide();

    AxMenuItem* GetMenuItem() const { return m_menuItem; }
    void SetMenuItem(AxMenuItem* item) { m_menuItem = item; }

    AxMenuController* GetController() const { return m_controller; }
    void SetController(AxMenuController* controller) { m_controller = controller; }

    const wxString& GetReturnCode() const { return m_returnCode; }
    void SetReturnCode(const wxString& code) { m_returnCode = code; }

    bool IsModal() const { return m_modalShowing; }
    void SetModal(bool modal) { m_modalShowing = modal; }

    void SetPreviousMenu(AxMenu* menu) { m_previousMenu = menu; }
    AxMenu* GetPreviousMenu() const { return m_previousMenu; }

    void SetMenu(AxMenu* menu) { m_menu = menu; }
    AxMenu* GetMenu() const { return m_menu; }

    bool RestorePreviousMenu();

protected:
    AxMenuItem*         m_menuItem;
    AxMenuController*   m_controller;
    wxString            m_returnCode;
    wxEventLoop*        m_eventLoop;
    bool                m_modalShowing;
    AxMenu*             m_menu;
    AxMenu*             m_previousMenu;
};

#endif
    // _AX_MENU_MODAL_H_
